
CXX      = g++
LINK     = g++
CXXFLAGS = -O2 -Wall -DDEBUG
#CXXFLAGS = -g -DDEBUG_ATPG -Wall #Turn on debugging
INCPATH  =
LIBS     = -lgmp -I ./include -L ./lib -lyices
#LIBS     = -lgmpxx -lgmp -I ./include -L ./lib -lyices -lcsisatcxx
DEL_FILE = rm -f

####### Files

HEADERS = typedef.h cfa.h ARF.h smt.h piped_process.h

SOURCES = ReadProg.tab.cc lex.yy.cc ARF.cc smt.cc piped_process.cpp werePrincessInterface.cpp PrincessFormulaParser.cpp
#OBJECTS = ReadProg.tab.o lex.yy.o main.o cfa.o art.o smt.o
OBJECTS = ReadProg.tab.o lex.yy.o ARF.o smt.o piped_process.o werePrincessInterface.o PrincessFormulaParser.o

TARGET  = backend.o

####### Implicit rules

.SUFFIXES: .o .cpp .cc .cxx

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< -g

####### Build rules
all: $(TARGET)

$(TARGET): $(OBJECTS)
	#$(LINK) $(CXXFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) $(INCPATH) -g
	#$(LINK) $(CXXFLAGS) -c $(OBJECTS) $(LIBS) $(INCPATH) -g
	ld -o back_end.o -r $(OBJECTS)

$(OBJECTS): $(HEADERS) Makefile

ReadProg.tab.cc: ReadProg.y
	bison -d -t ReadProg.y
	mv ReadProg.tab.c ReadProg.tab.cc

lex.yy.cc: ReadProg.l ReadProg.y
	flex ReadProg.l 
	mv lex.yy.c lex.yy.cc

clean:
	@$(DEL_FILE) $(TARGET)
	@$(DEL_FILE) ../obj/*.o
	@$(DEL_FILE) *.o
	@$(DEL_FILE) ReadProg.tab.cc ReadProg.tab.h lex.yy.cc

